package android.medicalcloud.com.yiapp.yilian.logic;

import android.medicalcloud.com.yiapp.base.cach.PreferceManager;
import android.medicalcloud.com.yiapp.base.net.lisener.ViewNetCallBack;
import android.medicalcloud.com.yiapp.base.utils.Logger;
import android.medicalcloud.com.yiapp.base.utils.MapBuilder;
import android.medicalcloud.com.yiapp.base.utils.StringTools;
import android.medicalcloud.com.yiapp.yilian.configer.enums.HttpConfig;
import android.medicalcloud.com.yiapp.yilian.model.BaseModeal;
import android.medicalcloud.com.yiapp.yilian.utils.net.ConnectTool;

/**
 * Created by wanggenlin on 17-5-18.
 */
public class UserController {
    static UserController instance;

    private  String loginKey="UserLocalKey";
    public static UserController getInstance() {
        if (instance == null) {
            instance = new UserController();
        }
        return instance;
    }
    /**
     * login
     */
    public void login(ViewNetCallBack viewNetCallBack, String userName,String pass) {


        try {
            ConnectTool.httpRequest(
                    HttpConfig.Login,
                    new MapBuilder<String, Object>()

                            .getMap()
                    , viewNetCallBack
                    , BaseModeal.class);
        } catch (Exception e) {
            Logger.e(e.getLocalizedMessage(), e);
        }
    }


    public void sendPinCode(ViewNetCallBack viewNetCallBack, String mobile) {


        try {
            ConnectTool.httpRequest(
                    HttpConfig.Login,
                    new MapBuilder<String, Object>()

                            .getMap()
                    , viewNetCallBack
                    , BaseModeal.class);
        } catch (Exception e) {
            Logger.e(e.getLocalizedMessage(), e);
        }
    }

    public boolean isLogin(){
        return !StringTools.isNullOrEmpty(userToken());
    }

    public String userToken(){
        String token = PreferceManager.getInsance().getValueBYkey(loginKey);
        return token;
    }

    public String saveToke(String token){
         PreferceManager.getInsance().saveValueBYkey(loginKey,token);
        return token;
    }

}
